<?php
require_once "wxshare.php";
$jssdk = new JSSDK("wxa03c93681e12093b", "0509cda6e10eab2caf2a03eef11a5d75");
$signPackage = $jssdk->GetSignPackage();
?>
<html>
<body>
<!--调用上传方法-->
<h1 id="scanCode">扫一扫</h1>
<input id="code" style="width:100%"></div>
<!--需要的js-->
<script src="//res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
<script src="./jquery.js"></script>
<script type="text/javascript">
function wxready(signPackage={},jsApiList=[]){
    wx.config({
        debug: false,
        appId: signPackage.appId,
        timestamp: signPackage.timestamp,
        nonceStr: signPackage.nonceStr,
        signature: signPackage.signature,
        jsApiList: jsApiList,
    })
    wx.ready(function () {
        wx.checkJsApi({
            jsApiList: jsApiList,
            success: function (res) {
                if (res.checkResult.getLocation == false) {
                    layer.msg('你的微信版本太低，不支持微信JS接口，请升级到最新的微信版本！');
                    return false;
                }
            }
        });
    })
}
    $(function () {
        signPackage = {
            appId: '<?php echo $signPackage["appId"];?>',
            timestamp: <?php echo $signPackage["timestamp"];?>,
            nonceStr: '<?php echo $signPackage["nonceStr"];?>',
            signature: '<?php echo $signPackage["signature"];?>',
        };
        jsApiList = [
                'scanQRCode'
            ];
        document.querySelector('#scanCode').onclick = function () {
            wxready(signPackage,jsApiList);
            wx.scanQRCode({
                needResult: 1,
                desc: 'scanCode desc',
                success: function (res) {
                    //扫码后获取结果参数:htpp://xxx.com/c/?6123，截取到url中的防伪码后，赋值给Input
                    var url = res.resultStr;
                    var tempArray = url.substring(url.lastIndexOf("/") + 1);
                    $('#code').val(url);
                    getInfoByErweima();
                    // if (tempArray.length > 20) {
                    //     tempArray = url.substring(url.length - 20);
                    // }
                    // location.href = "需要回传的页面地址" + tempArray;
                },
                error: function(res){
                     alert(333);
                    if(res.errMsg.indexOf('function_not_exist') > 0){
                        alert('版本过低请升级')
                    }
                }
            });
        }
    })
</script>
</body>
</html>
